﻿using System;
using System.Collections.Generic;
using System.Text;
using AD.DAL;
using AD.Model;
using System.Data;

namespace AD.BLL
{
    public class UserBLL : BLLBase
    {
        public static int Sum()
        {
            return SunFilter("");
        }
        public static int SunFilter(string filter)
        {
            return UserDAL.Sum(filter);
        }
        public static IList<UserMod> QueryByPage(string filter, int pageSize, int index, out int maxcount)
        {
            return UserDAL.QueryByPage(filter, pageSize, index, out maxcount);
        }
        public static int UpdateBalancePoint(int autoId, int balancePoint)
        {
            return UserDAL.UpdateBalancePoint(autoId, balancePoint);
        }
        public static int SetBalancePoint(int autoId, int balancePoint)
        {
            return UserDAL.SetBalancePoint(autoId, balancePoint);
        }
        public static int Insert(UserMod user)
        {
            return UserDAL.Insert(user);
        }

        public static UserMod CheckEmail(UserMod user)
        {
            return CheckEmail(user.Email);
        }

        public static UserMod CheckEmail(string email)
        {
            return UserDAL.CheckEmail(email);
        }

        public static UserMod SignUser(UserMod user, out int errorCode)
        {
            return SignUser(user.Email,user.Passwd, out errorCode);
            //errorCode = -1;
            //UserMod tmp = UserDAL.SignUser(user);
            //if (tmp == null)
            //    return null;
            //if (tmp.Passwd.Equals(user.Passwd))
            //{
            //    errorCode = 1;
            //    return tmp;
            //}
            //else
            //    errorCode = -2;
            //return null;
        }

        public static UserMod SignUser(string userName,string passwd, out int errorCode)
        {
            errorCode = -4;
            UserMod tmp = UserDAL.SignUser(userName, out errorCode);
            if (tmp == null)
                return null;
            if (tmp.Passwd.Equals(passwd))
            {
                errorCode = 1;
                return tmp;
            }
            else
                errorCode = -2;
            return null;
        }

        public static UserMod QueryByEmail(string email)
        {
            string filter = string.Format(" Email='{0}'", email);
            return UserDAL.QueryFrist(filter);
        }

        public static UserMod QueryById(int autoId)
        {
            return QueryById(autoId + "");
        }
        public static UserMod QueryById(string autoId)
        {
            string filter = string.Format(" AutoID='{0}'", autoId);
            return UserDAL.QueryFrist(filter);
        }
        public static DataTable QueryFilterToTable(string filter)
        {
            return UserDAL.QueryFilterToTable(filter);
        }

        public static List<UserMod> QueryFilterToList(string filter)
        {
            return UserDAL.QueryFilterToList(filter);
        }

        public static int UpdateOtherInfo(UserMod user)
        {
            return UserDAL.UpdateOtherInfo(user);
        }

        public static int UpdatePasswd(UserMod user)
        {
            return UserDAL.UpdatePasswd(user);
        }

        public static int DeleteById(int id)
        {
            string filter = " AutoID=" + id;
            return UserDAL.Delete(filter);
        }

        public static int Delete(UserMod user)
        {
            return DeleteById(user.AutoID);
        }
    }
}